package com.flash.BusinessParameters.service.impl;

import com.flash.BusinessParameters.entity.BondSetting;
import com.flash.BusinessParameters.entity.FundSetting;
import com.flash.BusinessParameters.mapper.BondSettingMapper;
import com.flash.BusinessParameters.service.BondSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BondSettingServiceImpl implements BondSettingService {

    @Autowired
    private BondSettingMapper bondSettingMapper;
    @Override
    public List<BondSetting> selectBondSettingMap(BondSetting bondSetting, int page, int limit) {
        Map map=new HashMap();
        map.put("strWhere",buildStrWhere(bondSetting));
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        return bondSettingMapper.selectBondSettingMap(map);
    }
    /**
     * 生成SQL条件
     * @param bondSetting 实体类
     * @return  条件的字符串  where 1=1 “   and userName  like '%admin%' and roleId =1 ”
     */
    public String buildStrWhere(BondSetting bondSetting){
        StringBuffer strWhere=new StringBuffer("");
        if(bondSetting.getBondId()!=null && !bondSetting.getBondId().equals(""))
        {
            strWhere.append("and bondId like '%" + bondSetting.getBondId() + "%'");
        }
        if(bondSetting.getBearingStart()!=null && !bondSetting.getBearingStart().equals(""))
        {
            System.out.println(bondSetting.getBearingStart());
            strWhere.append(" and bearingStart like '%" + bondSetting.getBearingStart()+"%'");
        }

        return strWhere.toString();
    }

    @Override
    public int deleteBondSetting(int bondId) {
        return bondSettingMapper.deleteBondSetting(bondId);
    }

    @Override
    public int insertBondSetting(BondSetting bondSetting) {
        return bondSettingMapper.insertBondSetting(bondSetting);
    }

    @Override
    public int updateBondSetting(BondSetting bondSetting) {
        return bondSettingMapper.updateBondSetting(bondSetting);
    }

    @Override
    public List<BondSetting> selectBondSetting() {
        return bondSettingMapper.selectBondSetting();
    }

    @Override
    public int selectCountBondSetting() {
        return bondSettingMapper.selectCountBondSetting();
    }
}
